package com.liuguang.common.pojo;

import com.liuguang.common.monitor.enums.CommonResultEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * @ClassName: CommonResult
 * @Description：
 * @Author: wanghr
 * Date: 5:53 PM 2020/9/11
 * Version: 1.0
 */
@Data
public class CommonResult<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;

    public CommonResult() {
    }

    public CommonResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public CommonResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    // 操作成功
    public static CommonResult success() {
        return new CommonResult(CommonResultEnum.SUCCESS.getCode(), CommonResultEnum.SUCCESS.getMsg());
    }

    public static CommonResult success(String msg) {
        return new CommonResult(CommonResultEnum.SUCCESS.getCode(), msg);
    }

    public static <T> CommonResult<T> success(String msg, T data) {
        return new CommonResult<T>(CommonResultEnum.SUCCESS.getCode(), msg, data);
    }

    // 操作失败
    public static CommonResult fail() {
        return new CommonResult(CommonResultEnum.FAIL.getCode(), CommonResultEnum.FAIL.getMsg());
    }

    public static CommonResult fail(String msg) {
        return new CommonResult(CommonResultEnum.FAIL.getCode(), msg);
    }

    public static <T> CommonResult<T> fail(String msg, T data) {
        return new CommonResult<T>(CommonResultEnum.FAIL.getCode(), msg, data);
    }
}
